import axios from 'axios'
import NProgress from 'nprogress'

// 开发模式  启用跨域
const BASE_URL = process.env.NODE_ENV === 'development' ? '/api' : 'http://123.207.32.32:9001'
export function request(config) {
  const instance = axios.create({
    baseURL: BASE_URL,
    timeout: 5000
  })
  // 请求拦截器
  instance.interceptors.request.use(config => {
    NProgress.start()
    // 伪造请求头
    config.headers.Authorization = window.sessionStorage.getItem('token')
    return config
  })

  // 响应拦截器
  instance.interceptors.response.use(response => {
    NProgress.done()
    return response
  })
  return instance(config)
}
